
def enum(**enums):
    return type('Enum', (), enums)
#end def

ds_idx = enum(
    year        = 0,    #A      1
    week        = 2,    #C      3
    local_reg   = 3,    #D      4
    sales_reg   = 4,    #E      5
    trade_line  = 6,    #G      7
    bond        = 7,    #H      8
    tue         = 9,    #J      10
    target      = 10,   #K      11
    fre_rev     = 12,   #M      13
    tar_rev     = 13,   #N      14
    oth_rev     = 21,   #V      22
)

import copy
def init_input_tab():
    return copy.deepcopy({
        "tue"       : {},
        "target"    : {},
        "fre_rev"    : {},
        "oth_rev"   : {},
        "tar_rev"   : {},
    })

def init_result_tab():
    return copy.deepcopy({
        "tue"           : {},
        "target"        : {},
        "last_tue"      : {},
        "acc_tue"       : {},
        "acc_target"    : {},
        "acc_last_tue"  : {},
        "fre_rev"       : {},
        "oth_rev"       : {},
        "tar_rev"       : {},
        "last_fre_rev"  : {},
        "last_oth_rev"  : {},
        "acc_fre_rev"   : {},
        "acc_oth_rev"   : {},
        "acc_tar_rev"   : {},
        "acc_last_fre_rev"  : {},
        "acc_last_oth_rev"  : {},
    })

def filter_OB(line, in_ds_idx):
    filter_tab={
        "AUS.S", 
        "AUZ.S",
        "IAG.W", 
        "IAR.W",
        "AUP.S", # new add in 2018-01-09
    }
    return line[in_ds_idx.bond] == "OB" and (line[in_ds_idx.trade_line] in filter_tab)

def filter_local(line):
    filter_tab={
        "AUS.S", 
        "AUZ.S",
        "IAG.W", 
        "IAR.W",
        "AUS.N", 
        "AUZ.N",
        "IAG.E", 
        "IAR.E",
        "AUP.S", # new add in 2018-01-09
        "AUP.N", # new add in 2018-01-09
        "IWA.W", # new add in 2024-03-13
        "IWA.E", # new add in 2024-03-13
    }
    return (line[ds_idx.trade_line] in filter_tab)


def filter_IB(line, in_ds_idx):
    filter_tab={
        "AUS.N", 
        "AUZ.N",
        "IAG.E", 
        "IAR.E",
        "AUP.N", # new add in 2018-01-09
        "IWA.W", # new add in 2024-03-13
        "IWA.E", # new add in 2024-03-13
    }
    return line[in_ds_idx.bond] == "IB" and (line[in_ds_idx.trade_line] in filter_tab)



ds_idx_1_2_3_2 = enum(
    year        = ord('A')-ord('A'),     #1
    week        = ord('C')-ord('A'),     #3
    sales_reg   = ord('D')-ord('A'),     #4
    sales_country  = ord('E')-ord('A'),     #5
    trade_line  = ord('G')-ord('A'),     #7
    bond        = ord('H')-ord('A'),     #8
    tue         = ord('J')-ord('A'),     #14-->10  changed in 2018-01-09
    target      = ord('K')-ord('A'),     #15-->11   changed in 2018-01-09
    fre_rev     = ord('M')-ord('A'),     #17-->13   changed in 2018-01-09
    tar_rev     = ord('N')-ord('A'),     #18-->14   changed in 2018-01-09
    oth_rev     = ord('V')-ord('A'),     #26-->22   changed in 2018-01-09
)                                                 
